import asyncio
import time
import aiohttp


# async def main():
#     # 异步上下文
#     async with aiohttp.ClientSession() as session:
#         # 发起异步请求
#         async with session.get('https://httpbin.org/get?age=1') as response:
#             # 等待异步结束 获取结果
#             r = await response.json()
#             print(r)
#
# start = time.time()
# # 启动异步任务
# asyncio.run(main())
# print(time.time() - start)

# async def fetch(session, url):
#     async with session.get(url) as response:
#         return await response.json()
#
# async def main():
#     async with aiohttp.ClientSession() as session:
#         result = await asyncio.gather(*[fetch(session, f'https://httpbin.org/get?age={i}') for i in range(1, 11)])
#         for r in result:
#             print(r)
#
# start = time.time()
# asyncio.run(main())
# print(time.time() - start)